"""

"""

from app.libs.http import HTTP
from flask import current_app

class YuShuBook:

    isbn_url = 'http://t.yushi.im/v2/book/isbn/{}'
    keyword_url = 'http://t.yushu.im/v2/book/search?q={}&count={}&start={}'

    # 使用isbn搜索
    @classmethod
    def search_by_isbn(cls, isbn):
        url = cls.isbn_url.format(isbn)
        result = HTTP.get(url)
        return result


    # 使用关键字搜索
    @classmethod
    def search_by_keyword(cls, keyword, page=1):
        url = cls.keyword_url.format(keyword, current_app.config['PER_PAGE'], cls.calculate_start(page))
        result = HTTP.get(url)
        return result


    # 计算当前起始条数
    @classmethod
    def calculate_start(cls, page):
        return (page - 1) * current_app.config['PER_PAGE']
